﻿using System;
using System.Collections.Generic;
using System.Web;
using umbraco.cms.businesslogic.datatype;

namespace TwentyTree4Umbraco.Datatypes
{
    public class VideoUploader : AbstractDataEditor
    {
        private TwentyTree4Umbraco.Controls.VideoUploader vu = new TwentyTree4Umbraco.Controls.VideoUploader();
        private VideoUploaderPrevalueEditor prevalueeditor;

        public override Guid Id
        {
            get
            {
                return new Guid("1E1E5024-04EC-11DF-BABA-62BA56D89593");
            }
        }

        public override string DataTypeName
        {
            get
            {
                return "23 VideoUploader";
            }
        }

        public override umbraco.interfaces.IDataPrevalue PrevalueEditor
        {
            get
            {
                if (prevalueeditor == null)
                    prevalueeditor = new VideoUploaderPrevalueEditor(this);
                return prevalueeditor;
            }

        }

        public VideoUploader()
        {
            base.RenderControl = vu;
            vu.Init += new EventHandler(vp_Init);
            base.DataEditorControl.OnSave += 
                new AbstractDataEditorControl.SaveEventHandler(DataEditorControl_OnSave);
        }

        void DataEditorControl_OnSave(EventArgs e)
        {
            vu.SaveFile();
            base.Data.Value = vu.Value;

        }

        void vp_Init(object sender, EventArgs e)
        {
            vu.AlbumID = (((VideoUploaderPrevalueEditor)PrevalueEditor).Configuration);
            vu.Value = base.Data.Value != null ? base.Data.Value.ToString() : "";
        }
    }
}
